﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.Services;
using System.Web.Management;
using System.DirectoryServices.AccountManagement;
using System.Configuration;
namespace ActiveDirectoryAuth.Account
{
    public partial class UserList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                if (!this.IsPostBack)
                {

                    /* PrincipalContext ctx = new PrincipalContext(ContextType.Domain,
                                                 User.Identity.Name,
                                                 ConfigurationSettings.AppSettings["container"].ToString());
                     */
                    PrincipalContext ctx = new PrincipalContext(ContextType.Domain, ConfigurationSettings.AppSettings["domain"].ToString(), ConfigurationSettings.AppSettings["container"].ToString()
                            , ConfigurationSettings.AppSettings["Admin_User_Name"].ToString(), ConfigurationSettings.AppSettings["Admin_User_Password"].ToString());





                    UserPrincipal usr = new UserPrincipal(ctx);


                    // Create a PrincipalSearcher object.
                    PrincipalSearcher ps = new PrincipalSearcher(usr);
                    PrincipalSearchResult<Principal> fr = ps.FindAll();
                    GridView1.DataSource = fr;
                    GridView1.DataBind();
                
                }
                

                
            }
        }
    }
}